/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
#include<stdio.h>
#include<stdlib.h>
 typedef struct Node{
    int data;
    struct Node* next;
 }List;
 //创建单链表
 void CreateList(List** L, int* a, int sz){
    (*L) = (List*)malloc(sizeof(List));
    List* tc = (*L), *s;
    int i;
    for(i = 0; i <sz; i++){
        s =  (List*)malloc(sizeof(List));
        s->data = a[i];
        tc->next = s;
        tc = s;
    }
    tc->next = NULL;
 }
 //查找最小值并且删除
 int DeleNum(List** L){
    List* p = (*L)->next;
    int i, min = p->data;
    p = p->next;
    while(p != NULL){
        if(p->data < min){
            min = p->data;
        }
        p = p->next;
    }

    p = (*L)->next;
    List *pre = (*L);
    while(p->data != min){
        pre = p;
        p = p->next;
    }
    pre->next = p->next;
    free(p);
    return min;
 }
int* numberGame(int* a, int sz, int* returnSize) {
    List* L;int i = 0, min1, min2;
    *returnSize = sz;

    int* arr = (int*)malloc(sizeof(int) * sz);
    CreateList(&L, a, sz);
    while(i < sz){
        min1 = DeleNum(&L);
        min2 = DeleNum(&L);
        arr[i] = min2;i++;
        arr[i] = min1;i++;
    }

    return arr;
}
int main1(){
    int a[] = {2, 5};
    int sz = 2;
    int* returnSize;
    int* arr = numberGame(a, sz, returnSize);
    for(int i = 0; i <sz; i++){
        printf("%d ", arr[i]);
    }
    return 0;
}